using JSOCTNetSDK.XmppModelFun;
using jsxmpp;
using System;

namespace JSOCTNetSDK.XmppTask
{
	public class MyServiceRequestHandler : ServiceRequestHandler
	{
		public delegate void DownRequestHandler(string fromUser, ServiceRequestParam requestParam, string id, string mode);

		public event MyServiceRequestHandler.DownRequestHandler OnDownRequestHandler;

		public override string getServiceId()
		{
			return System.DateTime.Now.Ticks.ToString();
		}

		public override int execute(string fromUser, ServiceRequestParam requestParam, string id, string mode)
		{
			int result = -1;
			try
			{
				System.Console.WriteLine("接到下发数据: " + requestParam.serviceId + " " + System.DateTime.Now.ToString());
				if (ConfigFile.IsPrintlog)
				{
					string json = ModelToJson.GetJson(requestParam);
					string strMessage = string.Format("接到下发数据:{0} ", json);
					XmppLogHelper.LogSDKDownData.Info(strMessage);
				}
				if (this.OnDownRequestHandler != null)
				{
					this.OnDownRequestHandler(fromUser, requestParam, id, mode);
				}
				result = 1;
			}
			catch (System.Exception ex)
			{
				XmppLogHelper.LogSDK.Error(ex);
			}
			return result;
		}
	}
}
